﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GapCCServerTest.GapCC;

namespace GapCCServerTest
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestGapCCHabits()
        {
            string testSchoolId = "TestSchool2";
            string testClassName = "TestClass";
            DateTime testStart = new DateTime(2008, 4, 1);
            DateTime testEnd = new DateTime(2008, 5, 1);

            Version_1SoapClient service = new Version_1SoapClient();

            GapCC.Habits habits = new GapCC.Habits();
            habits.SchoolId = testSchoolId;
            habits.ClassName = testClassName;
            habits.Start = testStart;
            habits.End = testEnd;

            habits.ClassRoomAverage = 1;
            habits.ComputersLeftOn = 2;
            habits.ComputersTotal = 3;
            habits.DeskLampsLeftOn = 4;
            habits.DeskLampsTotal = 5;
            habits.DVDsLeftOn = 6;
            habits.DVDsTotal = 7;
            habits.ExternalDoorsOpen = 8;
            habits.ExternalDoorsTotal = 9;
            habits.HallsAverage = 10;
            habits.HeatingOn = true;
            habits.InternalDoorsOpen = 12;
            habits.InternalDoorsTotal = 13;
            habits.LightBulbsLeftOn = 14;
            habits.LightBulbsTotal = 15;
            habits.MonitorsLeftOn = 16;
            habits.MonitorsTotal = 17;
            habits.PrintersLeftOn = 18;
            habits.PrintersTotal = 19;
            habits.RadiatorsObstructed = 20;
            habits.RadiatorsTotal = 21;
            habits.SickRoomAverage = 22;
            habits.TelevisionsLeftOn = 23;
            habits.TelevisionsTotal = 24;
            habits.WaterAverage = 25;
            habits.WhiteBoardsLeftOn = 26;
            habits.WhiteBoardsTotal = 27;
            habits.WindowsOpen = 28;
            habits.WindowsTotal = 29;

            Assert.IsTrue(service.SaveHabits(habits));

            Habits saved = service.GetHabits(testSchoolId, testClassName, testStart, testEnd);

            Assert.IsNotNull(saved);

            Assert.AreEqual(habits.SchoolId, saved.SchoolId);
            Assert.AreEqual(habits.ClassName, saved.ClassName);
            Assert.AreEqual(habits.Start, saved.Start);
            Assert.AreEqual(habits.End, saved.End);
            Assert.AreEqual(habits.ClassRoomAverage, saved.ClassRoomAverage);
            Assert.AreEqual(habits.ComputersLeftOn, saved.ComputersLeftOn);
            Assert.AreEqual(habits.ComputersTotal, saved.ComputersTotal);
            Assert.AreEqual(habits.DeskLampsLeftOn, saved.DeskLampsLeftOn);
            Assert.AreEqual(habits.DeskLampsTotal, saved.DeskLampsTotal);
            Assert.AreEqual(habits.DVDsLeftOn, saved.DVDsLeftOn);
            Assert.AreEqual(habits.DVDsTotal, saved.DVDsTotal);
            Assert.AreEqual(habits.ExternalDoorsOpen, saved.ExternalDoorsOpen);
            Assert.AreEqual(habits.ExternalDoorsTotal, saved.ExternalDoorsTotal);
            Assert.AreEqual(habits.HallsAverage, saved.HallsAverage);
            Assert.AreEqual(habits.HeatingOn, saved.HeatingOn);
            Assert.AreEqual(habits.InternalDoorsOpen, saved.InternalDoorsOpen);
            Assert.AreEqual(habits.InternalDoorsTotal, saved.InternalDoorsTotal);
            Assert.AreEqual(habits.LightBulbsLeftOn, saved.LightBulbsLeftOn);
            Assert.AreEqual(habits.LightBulbsTotal, saved.LightBulbsTotal);
            Assert.AreEqual(habits.MonitorsLeftOn, saved.MonitorsLeftOn);
            Assert.AreEqual(habits.MonitorsTotal, saved.MonitorsTotal);
            Assert.AreEqual(habits.PrintersLeftOn, saved.PrintersLeftOn);
            Assert.AreEqual(habits.PrintersTotal, saved.PrintersTotal);
            Assert.AreEqual(habits.RadiatorsObstructed, saved.RadiatorsObstructed);
            Assert.AreEqual(habits.RadiatorsTotal, saved.RadiatorsTotal);
            Assert.AreEqual(habits.SickRoomAverage, saved.SickRoomAverage);
            Assert.AreEqual(habits.TelevisionsLeftOn, saved.TelevisionsLeftOn);
            Assert.AreEqual(habits.TelevisionsTotal, saved.TelevisionsTotal);
            Assert.AreEqual(habits.WaterAverage, saved.WaterAverage);
            Assert.AreEqual(habits.WhiteBoardsLeftOn, saved.WhiteBoardsLeftOn);
            Assert.AreEqual(habits.WhiteBoardsTotal, saved.WhiteBoardsTotal);
            Assert.AreEqual(habits.WindowsOpen, saved.WindowsOpen);
            Assert.AreEqual(habits.WindowsTotal, saved.WindowsTotal);

        }

        [TestMethod]
        public void TestCarbonCalcultaion()
        {
            float margin = 0.01f;
            string testSchoolId = "TestSchool2";
            string testClassName = "TestClass";
            DateTime testStart = new DateTime(2008, 4, 1);
            DateTime testEnd = new DateTime(2008, 5, 1);

            Version_1SoapClient service = new Version_1SoapClient();

            CarbonCalculation calc = new CarbonCalculation();

            calc.SchoolId = testSchoolId;
            calc.ClassName = testClassName;
            calc.Start = testStart;
            calc.End = testEnd;

            calc.NoOfPupils = 77;
            calc.ElectricityKwh = 10000f;
            calc.RenewablePercentage = 0.12f;
            calc.GasKwh = 12f;
            calc.OilKwh = 13f;
            calc.OilLitres = 5f;
            calc.Butane45 = 2f;
            calc.Butane70 = 15f;
            calc.Butane150 = 14f;
            calc.Propane39 = 4f;
            calc.Propane60 = 5f;
            calc.Propane130 = 1f;
            calc.GreenElectricity = 120f;
            calc.RenewableOther = 240f;
            calc.SolarPanels = 122f;
            calc.WindTurbine = 17f;

            CarbonFootPrint footPrint = service.DoCarbonCalculation(calc);

            Assert.IsNotNull(footPrint);

            Assert.AreEqual(909.05328f, footPrint.ButaneTotal, margin);
            Assert.AreEqual(4602.40f, footPrint.ElectricityTotal, margin);
            Assert.AreEqual(2.22f, footPrint.GasTotal, margin);
            Assert.AreEqual(19.09f, footPrint.OilTotal, margin);
            Assert.AreEqual(166.950228f, footPrint.PropaneTotal, margin);
            Assert.AreEqual(5699.71f, footPrint.TonnesTotal, margin);

            Assert.AreEqual(11.81f, footPrint.ButanePerPupil, margin);
            Assert.AreEqual(59.77f, footPrint.ElectricityPerPupil, margin);
            Assert.AreEqual(0.03f, footPrint.GasPerPupil, margin);
            Assert.AreEqual(0.25f, footPrint.OilPerPupil, margin);
            Assert.AreEqual(2.17f, footPrint.PropanePerPupil, margin);
            Assert.AreEqual(74.02f, footPrint.TonnesPerPupil, margin);

        }

        [TestMethod]
        public void Test2()
        {
            float margin = 0.01f;
            string testSchoolId = "TestSchool2";
            string testClassName = "TestClass";
            DateTime testStart = new DateTime(2008, 4, 1);
            DateTime testEnd = new DateTime(2008, 5, 1);

            Version_1SoapClient service = new Version_1SoapClient();

            CarbonCalculation calc = new CarbonCalculation();

            calc.SchoolId = testSchoolId;
            calc.ClassName = testClassName;
            calc.Start = testStart;
            calc.End = testEnd;

            calc.NoOfPupils = 1;

            calc.ElectricityKwh = 1000f;
            calc.RenewablePercentage = 0.25f;
            calc.GasKwh = 900f;
            calc.OilKwh = 800f;
            calc.OilLitres = 100f;
            calc.Butane45 = 2f;
            calc.Butane70 = 0f;
            calc.Butane150 = 0f;
            calc.Propane39 = 10f;
            calc.Propane60 = 0f;
            calc.Propane130 = 1f;

            CarbonFootPrint footPrint = service.DoCarbonCalculation(calc);

            Assert.IsNotNull(footPrint);

            Assert.AreEqual(392.25f, footPrint.ElectricityTotal, margin);
            Assert.AreEqual(25.25f, footPrint.ButaneTotal, margin);
            Assert.AreEqual(166.5f, footPrint.GasTotal, margin);
            Assert.AreEqual(525.99f, footPrint.OilTotal, margin);
            Assert.AreEqual(148.15f, footPrint.PropaneTotal, margin);
            
            Assert.AreEqual(1258.14f, footPrint.TonnesTotal, margin);
        }

        [TestMethod]
        public void Test3()
        {
            float margin = 0.01f;
            string testSchoolId = "TestSchool2";
            string testClassName = "TestClass";
            DateTime testStart = new DateTime(2008, 4, 1);
            DateTime testEnd = new DateTime(2008, 5, 1);

            Version_1SoapClient service = new Version_1SoapClient();

            CarbonCalculation calc = new CarbonCalculation();

            calc.SchoolId = testSchoolId;
            calc.ClassName = testClassName;
            calc.Start = testStart;
            calc.End = testEnd;

            calc.NoOfPupils = 1;
            calc.ElectricityKwh = 1250f;
            calc.RenewablePercentage = 0.05f;
            calc.GasKwh = 1234f;
            calc.OilKwh = null;
            calc.OilLitres = 400f;
            calc.Butane45 = 0f;
            calc.Butane70 = 11f;
            calc.Butane150 = 1f;
            calc.Propane39 = 0f;
            calc.Propane60 = 2f;
            calc.Propane130 = 12f;

            CarbonFootPrint footPrint = service.DoCarbonCalculation(calc);

            Assert.IsNotNull(footPrint);

            Assert.AreEqual(258.13f, footPrint.ButaneTotal, margin);
            Assert.AreEqual(621.06f, footPrint.ElectricityTotal, margin);
            Assert.AreEqual(228.29f, footPrint.GasTotal, margin);
            Assert.AreEqual(1249.56f, footPrint.OilTotal, margin);
            Assert.AreEqual(478.63f, footPrint.PropaneTotal, margin);
            Assert.AreEqual(2835.67f, footPrint.TonnesTotal, margin);
        }
    }
}
